package cn.msqweb.ex.handler;


import cn.msqweb.constant.BusinessEnum;
import cn.msqweb.ex.handler.ex.BusinessException;
import cn.msqweb.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理类
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public Result<String> businessHandler(BusinessException e) {
        log.error(e.toString());
        return Result.fail(BusinessEnum.OPERATION_FAIL.getCode(),e.getMessage());
    }
}
